package com.ruoyi.web.controller.mobile;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.supervise.domain.BaseProjectInfo;
import com.ruoyi.supervise.domain.ProjectArchives;
import com.ruoyi.supervise.service.IProjectArchivesBaseInfoService;
import com.ruoyi.supervise.service.IProjectArchivesService;

import cn.hutool.core.util.StrUtil;

/**
 * @ClassName: MobileProject
 * @Description: 手机端获取项目接口
 * @Author wtj
 * @DateTime 2020-9-11 10:51:34
 */
@Controller
@RequestMapping("/mobile/projectArchives")
public class MobileProject {
	
	@Autowired
    private IProjectArchivesService projectArchivesService;
	
	@Autowired
    private IProjectArchivesBaseInfoService projectArchivesBaseInfoService;
	
	/**
	 * @Title: list
	 * @Description: 手机端获取项目列表
	 * @Author wtj
	 * @DateTime 2020-9-11 10:51:13
	 * @param projectArchives
	 * @return
	 */
	@PostMapping("/list")
	@ResponseBody
    public AjaxResult list(ProjectArchives projectArchives)
    {
		List<ProjectArchives> projectArchivesList = projectArchivesService.selectProjectArchivesList(projectArchives);
        //数据库中Base_ProjectInfo表中的ConstructUnitId字段的类型如下:"|海南定安天九美食文化广场有限公司"是正确的ConstructUnitId，其他的都是非法的
        projectArchivesList.forEach(pa ->{
        	String[] subStr=StrUtil.split(pa.getConstructUnitId(), "|");
        	if(subStr.length == 2) {
        		pa.setConstructUnitId(subStr[1]);
        	}else {
        		pa.setConstructUnitId(" ");
        	}
        });
        return AjaxResult.success("获取项目列表成功",projectArchivesList);
    }
	
	/**
	 * @Title: detail
	 * @Description: 手机端获取项目详情接口
	 * @Author wtj
	 * @DateTime 2020-9-11 11:00:21
	 * @param guid
	 * @param projectArchivesBaseInfo
	 * @return
	 */
   @GetMapping("/detail")
   @ResponseBody
   public AjaxResult detail(String guid)
   {
	   BaseProjectInfo projectArchivesBaseInfo = new BaseProjectInfo();
	   projectArchivesBaseInfo.setGuid(guid);
	   BaseProjectInfo pabi=projectArchivesBaseInfoService.selectProjectArchivesBaseInfoByGuid(projectArchivesBaseInfo);
	   boolean is=StrUtil.containsAnyIgnoreCase(pabi.getProjectType(), "市政");
	   if(pabi.getProjectType().equals("私人住宅")) {
		   pabi.setProjectType("私人住宅");
	   }else {
		   if(is) {
			   pabi.setProjectType("市政基础设施工程");
		   }else {
			   pabi.setProjectType("房屋建筑工程");
		   }
	   }
	   return AjaxResult.success("获取项目详情成功",pabi);
   }
}
